﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;

using TracedReality.Logging;

namespace Interface.Logging
{
    public class FileLog : LogReceiver
    {
        private string filename;
        private List<string> buffer;

        public FileLog(string s) { filename = s; buffer = new List<string>(); }

        public void giveString(string str)
        {
            buffer.Add(str);

            if (buffer.Count > 10)
            {
                using (StreamWriter writer = new StreamWriter(filename, true))
                {
                    foreach (string line in buffer) { writer.WriteLine(line); }
                }

                buffer.Clear();
            }
        }

        public void flush()
        {
            if (buffer.Count > 0)
            {
                using (StreamWriter writer = new StreamWriter(filename, true))
                {
                    foreach (string line in buffer) { writer.WriteLine(line); }
                }

                buffer.Clear();
            }
        }
    }
}
